

package com.hazelcast.function;

import com.hazelcast.security.impl.function.SecuredFunction;

import java.io.Serializable;
import java.util.function.Consumer;

import static com.hazelcast.internal.util.Preconditions.checkNotNull;

/**
 * {@code Serializable} variant of {@link Consumer java.util.function.Consumer}
 * which declares checked exception.
 *
 * @param <T> the type of the input to the operation
 * @since 4.0
 */
@FunctionalInterface
public interface ConsumerEx<T> extends ThrowingConsumer<T>, Serializable, SecuredFunction {

    /**
     * Returns a consumer that does nothing.
     *
     * @param <T> the consumer input type
     */
    static <T> ConsumerEx<T> noop() {
        return x -> {
        };
    }

    /**
     * {@code Serializable} variant of {@link Consumer#andThen(Consumer)
     * java.util.function.Consumer#andThen(Consumer)}.
     */
    default ConsumerEx<T> andThen(ConsumerEx<? super T> after) {
        checkNotNull(after, "after");
        return new FunctionsImpl.ComposedConsumerEx<>(this, after);
    }
}
